<?php
/**
 *
 * IndexAction.class.php (前台首页)
 *
 * @package      	jgsat
 * @author          liuxun QQ:147613338 <admin@jgsat.cn>
 * @copyright     	Copyright (c) 2008-2011  (http://www.jgsat.com)
 * @license         http://www.jgsat.com/license.txt
 * @version        	jgsat企业网站管理系统 v2.1 2011-03-01 jgsat.cn $
 */
if(!defined("JGsat")) exit("Access Denied");
class UserAction extends BaseAction
{

	//个人主页
	public function index($catid='',$module='')
	{
		$this->Urlrule =F('Urlrule');

		$id =  intval($_REQUEST['id']);
		$pege=intval($_GET['p']);
		if(empty($pege)){$pege=0;}
		$of=$pege*4;
		$this->dao= M('User');
		$data = $this->dao->find($id);
		//设计师作品
		if($data['groupid']=='1') {
			$this->dao_case = M('Case');
			$data_case = $this->dao_case->where('userid=' . $id." and status=1")->order('id desc')->limit($of . ',4')->select();
			//echo $this->dao_case->getLastSql();exit;
		}
		//供应商商品
		if($data['groupid']=='3') {
			$this->dao_product = M('Product');
			$data_product= $this->dao_product->where('userid=' . $id." and status=1")->order('id desc')->limit($of . ',4')->select();
		}

		$data_keep = M('Keep')->where('userid='.$id)->order('id desc')->limit('10')->select();//收藏

		//评论
		$field='jg_comment.id,jg_comment.content,jg_comment.createtime,jg_user.avatar,jg_user.username,jg_user.id as userid';
		$where='jg_Comment.`conid`='.$id.' and jg_Comment.`contype`=\'User\'';
		$data_comment=M('Comment')->field($field)->where($where)->join('jg_user ON jg_comment.userid = jg_user.id')->order('jg_comment.id desc')->limit('4')->select();

		//发布的帖子
		$list_theme = M('Zforum_theme')->where('userid=' . $id)->order('createtime desc,id desc')->limit(10)->select();

		//设计师作品AJAX分页
		if($_GET['p']){
			$itemType = M('Label')->where("genre=17")->limit(50)->select();
			$style = M('Label')->where("genre=21")->limit(50)->select();
			foreach($data_case as $k=>$v){
				foreach($itemType as $key=>$r) {
					if($v['itemType'] = $r['id']){
						$data_case[$k]['itemtype']=$r['title'];
					}
				}
				foreach($style as $key=>$r) {
					if($v['style'] = $r['id']){
						$data_case[$k]['style']=$r['title'];
					}
				}
			}
			if(empty($data_case)){
				echo 1;
			}else {

				$p = $_GET['p'] + 1;
				$list = array('data_case' => $data_case, 'p' => $p, 'id' => $id);
				echo json_encode($list);//转换格式
			}

		}else {
			$this->assign('keep',$data_keep);
			$this->assign('case', $data_case);
			$this->assign('list_theme', $list_theme);
			$this->assign('comment', $data_comment);
			$this->assign('data_product',$data_product);
			$this->assign('id', $id);
			$this->assign('userid', $this->_userid);
			$this->assign($data);


			if($data['groupid']=='1') {
				$this->display();
			}
			if($data['groupid']=='2') {
				$this->display('index2');//业主中心
			}
			if($data['groupid']=='3') {
				$this->display('index3');//供应商中心
			}
		}
	}
	public function show(){

		header("Location: index.php?m=User&a=index&id=".$_GET['id']);
	}

	public function keep(){

		$id = intval($_REQUEST['id']);
		$pege=intval($_GET['p']);
		if(empty($pege)){$pege=0;}
		$of=$pege*10;
		$data_keep = M('Keep')->where('userid='.$id)->order('id desc')->limit($of.',10')->select();
		if($_GET['p']){
			if(empty($data_keep)){
				echo 1;
			}else {

				$p = $_GET['p'] + 1;
				$list = array('data_keep' => $data_keep, 'p' => $p, 'id' => $id);
				echo json_encode($list);//转换格式
			}

		}
	}

	public function comment(){

		$id = intval($_REQUEST['id']);
		$pege=intval($_GET['p']);
		if(empty($pege)){$pege=0;}
		$of=$pege*4;
		$field='jg_comment.id,jg_comment.content,jg_comment.createtime,jg_user.avatar,jg_user.username,jg_user.id as userid';
		$where='jg_Comment.`conid`='.$id.' and jg_Comment.`contype`=\'User\'';
		$data_comment=M('Comment')->field($field)->where($where)->join('jg_user ON jg_comment.userid = jg_user.id')->order('jg_comment.id desc')->limit($of.',4')->select();

		if($_GET['p']){
			if(empty($data_comment)){
				echo 1;
			}else {

				$p = $_GET['p'] + 1;
				$list = array('data_comment' => $data_comment, 'p' => $p, 'id' => $id);
				echo json_encode($list);//转换格式
			}

		}
	}

	public function theme(){

		$id = intval($_REQUEST['id']);
		$pege=intval($_GET['p']);
		if(empty($pege)){$pege=0;}
		$of=$pege*10;
		$list_theme = M('Zforum_theme')->where('userid='.$id)->order('id desc')->limit($of.',10')->select();
		if($_GET['p']){
			if(empty($list_theme)){
				echo 1;exit;
			}else {

				$p = $_GET['p'] + 1;
				$list = array('list_theme' => $list_theme, 'p' => $p, 'id' => $id);
				echo json_encode($list);//转换格式
			}

		}
	}


}
?>